//
//  TopView.m
//  day-02-TopView
//
//  Created by hcios on 2017/6/30.
//  Copyright © 2017年 hcios. All rights reserved.
//

#import "TopView.h"
#import "UIImageView+WebCache.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width

#define kScreenHeight [UIScreen mainScreen].bounds.size.height


@implementation TopView

-(void)layoutSubviews{
    NSLog(@"调用");
}

-(void)layoutSubviewsMinString:(NSString *)minString withMaxString:(NSString *)maxString andDaysString:(NSString *)daysString withURL:(NSString *)imageUrl{
    
    _bgImageview = [[UIImageView alloc] initWithFrame:self.bounds]; //这里之前我使用的是self.frame，出现了bug，注意要使用bounds
    
    _bgImageview.userInteractionEnabled = YES;
    [_bgImageview sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"zhanWeiTu"]];
    [self addSubview:_bgImageview];
    
    //最低温度
    _minLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, kScreenWidth / 3, 80)];
    _minLab.textAlignment = NSTextAlignmentRight;
    _minLab.shadowColor = [UIColor blackColor];
    _minLab.shadowOffset = CGSizeMake(1, 1);
    _minLab.textColor = [UIColor cyanColor];
    _minLab.font = [UIFont systemFontOfSize:40];
    _minLab.text = minString;
    [_bgImageview addSubview:_minLab];
    
    //分割线
    _lineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_minLab.frame) + 50, 90, 25, 2)];
    _lineView.backgroundColor = [UIColor whiteColor];
    [_bgImageview addSubview:_lineView];
    
    //最高温度
    _maxLab = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_lineView.frame) + 50, 50, kScreenWidth / 3, 80)];
    _maxLab.textAlignment = NSTextAlignmentLeft;
    _maxLab.textColor = [UIColor redColor];
    _maxLab.font = [UIFont systemFontOfSize:40];
    _maxLab.shadowColor = [UIColor blackColor];
    _maxLab.shadowOffset = CGSizeMake(1, 1);
    _maxLab.text = maxString;
    [_bgImageview addSubview:_maxLab];
    
    //天数和时间
    _daysLab = [[UILabel alloc] initWithFrame:CGRectMake((kScreenWidth - 150) / 2, CGRectGetMaxY(_minLab.frame) + 10, 150, 20)];
    _daysLab.textAlignment = NSTextAlignmentCenter;
    _daysLab.font = [UIFont systemFontOfSize:13];
    _daysLab.textColor = [UIColor whiteColor];
    _daysLab.shadowColor = [UIColor blackColor];
    _daysLab.shadowOffset = CGSizeMake(1, 1);
    _daysLab.text = [NSString stringWithFormat:@"当地时间：%@",daysString];
    [_bgImageview addSubview:_daysLab];
}

-(void)setModel:(WeatherModel *)model{
    
    _model = model;
    _minLab.text = model.temp_min;
    _maxLab.text = model.temp_max;
    _daysLab.text = [NSString stringWithFormat:@"当地时间：%@",model.current_time];
}


@end
